﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace XWord.Fundamental.Domain
{
    [Serializable]
    [DataContract]
    public class EtymaLibrary : Entity
    {
        [DataMember]
        public virtual string Comment { get; set; }

        [DataMember]
        public virtual int WordIndex { get; set; }

        private void ParseEtyma(string text)
        {

            if (text.EndsWith("-"))
            {
                this.EtymaType = EtymaType.PreFix;
            }
            else if (text.StartsWith("-") && !text.EndsWith("+"))
            {
                this.EtymaType = EtymaType.Suffix;
            }
            else if (text.EndsWith("+"))
            {
                this.EtymaType = EtymaType.Etymon;
            }
            else
            {
                this.EtymaType = EtymaType.Suffix;
            }

        }

        private EtymaType _etymaType;
        [DataMember]
        public virtual EtymaType EtymaType
        {
            get
            {
                if (_etymaType == EtymaType.None)
                {
                    ParseEtyma(Name);
                    _etymaType = _etymaType ^ EtymaType.None;
                }
                return _etymaType;
            }
            set
            {
                _etymaType = value;
            }
        }
    }
}
